package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @PostMapping
    public Result insert(@RequestBody Clazz clazz){
        log.info("新增班级信息，参数：{}", clazz);
        clazzService.insert(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("根据id查询班级信息，参数：{}", id);
        Clazz clazz = clazzService.selectById(id);
        return Result.success(clazz);
    }

    @GetMapping("/list")
    public Result selectAll(){
        log.info("查询所有班级信息");
        return Result.success(clazzService.selectAll());
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("根据id删除班级信息，参数：{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }

    @PutMapping
    public Result put(@RequestBody Clazz clazz){
        log.info("修改班级信息，参数：{}", clazz);
        clazzService.put(clazz);
        return Result.success();
    }

    @GetMapping
    public Result page(ClazzQueryParam param){
        log.info("分页查询班级信息，参数：{}", param);
        PageResult<Clazz> pageResult = clazzService.page(param);
        return Result.success(pageResult);
    }
}
